<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module BigMath - bigdecimal: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-exp">::exp</a>
    <li ><a href="#method-c-log">::log</a>
    <li ><a href="#method-i-E">#E</a>
    <li ><a href="#method-i-PI">#PI</a>
    <li ><a href="#method-i-atan">#atan</a>
    <li ><a href="#method-i-cos">#cos</a>
    <li ><a href="#method-i-sin">#sin</a>
    <li ><a href="#method-i-sqrt">#sqrt</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-BigMath">
    <h1 id="module-BigMath" class="module">
      module BigMath
    </h1>

    <section class="description">
    
<p>Provides mathematical functions.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;bigdecimal/math&quot;</span>

<span class="ruby-identifier">include</span> <span class="ruby-constant">BigMath</span>

<span class="ruby-identifier">a</span> = <span class="ruby-constant">BigDecimal</span>((<span class="ruby-constant">PI</span>(<span class="ruby-value">100</span>)<span class="ruby-operator">/</span><span class="ruby-value">2</span>).<span class="ruby-identifier">to_s</span>)
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">sin</span>(<span class="ruby-identifier">a</span>,<span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; 0.99999999999999999999......e0</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-exp" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          exp(decimal, numeric)    &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the value of e (the base of natural logarithms) raised to the power of <code>decimal</code>, to the specified number of digits of precision.</p>

<p>If <code>decimal</code> is infinity, returns Infinity.</p>

<p>If <code>decimal</code> is NaN, returns NaN.</p>

                              <div class="method-source-code" id="exp-source">
            <pre>static VALUE
BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
{
    ssize_t prec, n, i;
    Real* vx = NULL;
    VALUE one, d, y;
    int negative = 0;
    int infinite = 0;
    int nan = 0;
    double flo;

    prec = NUM2SSIZET(vprec);
    if (prec &lt;= 0) {
        rb_raise(rb_eArgError, &quot;Zero or negative precision for exp&quot;);
    }

    /* TODO: the following switch statement is almost same as one in the
     *       BigDecimalCmp function. */
    switch (TYPE(x)) {
      case T_DATA:
        if (!is_kind_of_BigDecimal(x)) break;
        vx = DATA_PTR(x);
        negative = BIGDECIMAL_NEGATIVE_P(vx);
        infinite = VpIsPosInf(vx) || VpIsNegInf(vx);
        nan = VpIsNaN(vx);
        break;

      case T_FIXNUM:
        /* fall through */
      case T_BIGNUM:
        vx = GetVpValue(x, 0);
        break;

      case T_FLOAT:
        flo = RFLOAT_VALUE(x);
        negative = flo &lt; 0;
        infinite = isinf(flo);
        nan = isnan(flo);
        if (!infinite &amp;&amp; !nan) {
            vx = GetVpValueWithPrec(x, 0, 0);
        }
        break;

      case T_RATIONAL:
        vx = GetVpValueWithPrec(x, prec, 0);
        break;

      default:
        break;
    }
    if (infinite) {
        if (negative) {
            return VpCheckGetValue(GetVpValueWithPrec(INT2FIX(0), prec, 1));
        }
        else {
            Real* vy = NewZeroWrapNolimit(1, prec);
            VpSetInf(vy, VP_SIGN_POSITIVE_INFINITE);
            RB_GC_GUARD(vy-&gt;obj);
            return VpCheckGetValue(vy);
        }
    }
    else if (nan) {
        Real* vy = NewZeroWrapNolimit(1, prec);
        VpSetNaN(vy);
        RB_GC_GUARD(vy-&gt;obj);
        return VpCheckGetValue(vy);
    }
    else if (vx == NULL) {
        cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
    }
    x = vx-&gt;obj;

    n = prec + BIGDECIMAL_DOUBLE_FIGURES;
    negative = BIGDECIMAL_NEGATIVE_P(vx);
    if (negative) {
        VALUE x_zero = INT2NUM(1);
        VALUE x_copy = f_BigDecimal(1, &amp;x_zero, klass);
        x = BigDecimal_initialize_copy(x_copy, x);
        vx = DATA_PTR(x);
        VpSetSign(vx, 1);
    }

    one = VpCheckGetValue(NewOneWrapLimited(1, 1));
    y   = one;
    d   = y;
    i   = 1;

    while (!VpIsZero((Real*)DATA_PTR(d))) {
        SIGNED_VALUE const ey = VpExponent10(DATA_PTR(y));
        SIGNED_VALUE const ed = VpExponent10(DATA_PTR(d));
        ssize_t m = n - vabs(ey - ed);

        rb_thread_check_ints();

        if (m &lt;= 0) {
            break;
        }
        else if ((size_t)m &lt; BIGDECIMAL_DOUBLE_FIGURES) {
            m = BIGDECIMAL_DOUBLE_FIGURES;
        }

        d = BigDecimal_mult(d, x);                             /* d &lt;- d * x */
        d = BigDecimal_div2(d, SSIZET2NUM(i), SSIZET2NUM(m));  /* d &lt;- d / i */
        y = BigDecimal_add(y, d);                              /* y &lt;- y + d  */
        ++i;                                                   /* i  &lt;- i + 1 */
    }

    if (negative) {
        return BigDecimal_div2(one, y, vprec);
    }
    else {
        vprec = SSIZET2NUM(prec - VpExponent10(DATA_PTR(y)));
        return BigDecimal_round(1, &amp;vprec, y);
    }

    RB_GC_GUARD(one);
    RB_GC_GUARD(x);
    RB_GC_GUARD(y);
    RB_GC_GUARD(d);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-log" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          log(decimal, numeric)    &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the natural logarithm of <code>decimal</code> to the specified number of digits of precision, <code>numeric</code>.</p>

<p>If <code>decimal</code> is zero or negative, raises Math::DomainError.</p>

<p>If <code>decimal</code> is positive infinity, returns Infinity.</p>

<p>If <code>decimal</code> is NaN, returns NaN.</p>

                              <div class="method-source-code" id="log-source">
            <pre>static VALUE
BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
{
    ssize_t prec, n, i;
    SIGNED_VALUE expo;
    Real* vx = NULL;
    VALUE vn, one, two, w, x2, y, d;
    int zero = 0;
    int negative = 0;
    int infinite = 0;
    int nan = 0;
    double flo;
    long fix;

    if (!is_integer(vprec)) {
        rb_raise(rb_eArgError, &quot;precision must be an Integer&quot;);
    }

    prec = NUM2SSIZET(vprec);
    if (prec &lt;= 0) {
        rb_raise(rb_eArgError, &quot;Zero or negative precision for exp&quot;);
    }

    /* TODO: the following switch statement is almost same as one in the
     *       BigDecimalCmp function. */
    switch (TYPE(x)) {
      case T_DATA:
          if (!is_kind_of_BigDecimal(x)) break;
          vx = DATA_PTR(x);
          zero = VpIsZero(vx);
          negative = BIGDECIMAL_NEGATIVE_P(vx);
          infinite = VpIsPosInf(vx) || VpIsNegInf(vx);
          nan = VpIsNaN(vx);
          break;

      case T_FIXNUM:
        fix = FIX2LONG(x);
        zero = fix == 0;
        negative = fix &lt; 0;
        goto get_vp_value;

      case T_BIGNUM:
        i = FIX2INT(rb_big_cmp(x, INT2FIX(0)));
        zero = i == 0;
        negative = i &lt; 0;
get_vp_value:
        if (zero || negative) break;
        vx = GetVpValue(x, 0);
        break;

      case T_FLOAT:
        flo = RFLOAT_VALUE(x);
        zero = flo == 0;
        negative = flo &lt; 0;
        infinite = isinf(flo);
        nan = isnan(flo);
        if (!zero &amp;&amp; !negative &amp;&amp; !infinite &amp;&amp; !nan) {
            vx = GetVpValueWithPrec(x, 0, 1);
        }
        break;

      case T_RATIONAL:
        zero = RRATIONAL_ZERO_P(x);
        negative = RRATIONAL_NEGATIVE_P(x);
        if (zero || negative) break;
        vx = GetVpValueWithPrec(x, prec, 1);
        break;

      case T_COMPLEX:
        rb_raise(rb_eMathDomainError,
                 &quot;Complex argument for BigMath.log&quot;);

      default:
        break;
    }
    if (infinite &amp;&amp; !negative) {
        Real *vy = NewZeroWrapNolimit(1, prec);
        RB_GC_GUARD(vy-&gt;obj);
        VpSetInf(vy, VP_SIGN_POSITIVE_INFINITE);
        return VpCheckGetValue(vy);
    }
    else if (nan) {
        Real* vy = NewZeroWrapNolimit(1, prec);
        RB_GC_GUARD(vy-&gt;obj);
        VpSetNaN(vy);
        return VpCheckGetValue(vy);
    }
    else if (zero || negative) {
        rb_raise(rb_eMathDomainError,
                 &quot;Zero or negative argument for log&quot;);
    }
    else if (vx == NULL) {
        cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
    }
    x = VpCheckGetValue(vx);

    one = VpCheckGetValue(NewOneWrapLimited(1, 1));
    two = VpCheckGetValue(VpCreateRbObject(1, &quot;2&quot;, true));

    n = prec + BIGDECIMAL_DOUBLE_FIGURES;
    vn = SSIZET2NUM(n);
    expo = VpExponent10(vx);
    if (expo &lt; 0 || expo &gt;= 3) {
        char buf[DECIMAL_SIZE_OF_BITS(SIZEOF_VALUE * CHAR_BIT) + 4];
        snprintf(buf, sizeof(buf), &quot;1E%&quot;PRIdVALUE, -expo);
        x = BigDecimal_mult2(x, VpCheckGetValue(VpCreateRbObject(1, buf, true)), vn);
    }
    else {
        expo = 0;
    }
    w = BigDecimal_sub(x, one);
    x = BigDecimal_div2(w, BigDecimal_add(x, one), vn);
    x2 = BigDecimal_mult2(x, x, vn);
    y = x;
    d = y;
    i = 1;
    while (!VpIsZero((Real*)DATA_PTR(d))) {
        SIGNED_VALUE const ey = VpExponent10(DATA_PTR(y));
        SIGNED_VALUE const ed = VpExponent10(DATA_PTR(d));
        ssize_t m = n - vabs(ey - ed);
        if (m &lt;= 0) {
            break;
        }
        else if ((size_t)m &lt; BIGDECIMAL_DOUBLE_FIGURES) {
            m = BIGDECIMAL_DOUBLE_FIGURES;
        }

        x = BigDecimal_mult2(x2, x, vn);
        i += 2;
        d = BigDecimal_div2(x, SSIZET2NUM(i), SSIZET2NUM(m));
        y = BigDecimal_add(y, d);
    }

    y = BigDecimal_mult(y, two);
    if (expo != 0) {
        VALUE log10, vexpo, dy;
        log10 = BigMath_s_log(klass, INT2FIX(10), vprec);
        vexpo = VpCheckGetValue(GetVpValue(SSIZET2NUM(expo), 1));
        dy = BigDecimal_mult(log10, vexpo);
        y = BigDecimal_add(y, dy);
    }

    RB_GC_GUARD(one);
    RB_GC_GUARD(two);
    RB_GC_GUARD(vn);
    RB_GC_GUARD(x2);
    RB_GC_GUARD(y);
    RB_GC_GUARD(d);

    return y;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          E(numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes e (the base of natural logarithms) to the specified number of digits of precision, <code>numeric</code>.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-constant">E</span>(<span class="ruby-value">10</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;0.271828182845904523536028752390026306410273e1&quot;</span>
</pre>

                              <div class="method-source-code" id="E-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 228</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">E</span>(<span class="ruby-identifier ruby-title">prec</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Zero or negative precision for E&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
  <span class="ruby-constant">BigMath</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-value">1</span>, <span class="ruby-identifier">prec</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-PI" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          PI(numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the value of pi to the specified number of digits of precision, <code>numeric</code>.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-constant">PI</span>(<span class="ruby-value">10</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;0.3141592653589793238462643388813853786957412e1&quot;</span>
</pre>

                              <div class="method-source-code" id="PI-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 183</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PI</span>(<span class="ruby-identifier ruby-title">prec</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Zero or negative precision for PI&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
  <span class="ruby-identifier">n</span>      = <span class="ruby-identifier">prec</span> <span class="ruby-operator">+</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
  <span class="ruby-identifier">zero</span>   = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;0&quot;</span>)
  <span class="ruby-identifier">one</span>    = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;1&quot;</span>)
  <span class="ruby-identifier">two</span>    = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;2&quot;</span>)

  <span class="ruby-identifier">m25</span>    = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;-0.04&quot;</span>)
  <span class="ruby-identifier">m57121</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;-57121&quot;</span>)

  <span class="ruby-identifier">pi</span>     = <span class="ruby-identifier">zero</span>

  <span class="ruby-identifier">d</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">k</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">t</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;-80&quot;</span>)
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">m</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">pi</span>.<span class="ruby-identifier">exponent</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">exponent</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
    <span class="ruby-identifier">t</span>   = <span class="ruby-identifier">t</span><span class="ruby-operator">*</span><span class="ruby-identifier">m25</span>
    <span class="ruby-identifier">d</span>   = <span class="ruby-identifier">t</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">k</span>   = <span class="ruby-identifier">k</span><span class="ruby-operator">+</span><span class="ruby-identifier">two</span>
    <span class="ruby-identifier">pi</span>  = <span class="ruby-identifier">pi</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">d</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">d</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">k</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">t</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;956&quot;</span>)
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">m</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">pi</span>.<span class="ruby-identifier">exponent</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">exponent</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
    <span class="ruby-identifier">t</span>   = <span class="ruby-identifier">t</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">m57121</span>,<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">d</span>   = <span class="ruby-identifier">t</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">pi</span>  = <span class="ruby-identifier">pi</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">d</span>
    <span class="ruby-identifier">k</span>   = <span class="ruby-identifier">k</span><span class="ruby-operator">+</span><span class="ruby-identifier">two</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">pi</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-atan" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          atan(decimal, numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the arctangent of <code>decimal</code> to the specified number of digits of precision, <code>numeric</code>.</p>

<p>If <code>decimal</code> is NaN, returns NaN.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-identifier">atan</span>(<span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&#39;-1&#39;</span>), <span class="ruby-value">16</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;-0.785398163397448309615660845819878471907514682065e0&quot;</span>
</pre>

                              <div class="method-source-code" id="atan-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 146</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">atan</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">prec</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Zero or negative precision for atan&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;NaN&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nan?</span>
  <span class="ruby-identifier">pi</span> = <span class="ruby-constant">PI</span>(<span class="ruby-identifier">prec</span>)
  <span class="ruby-identifier">x</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">x</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">neg</span> = <span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">pi</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">neg</span> <span class="ruby-operator">?</span> <span class="ruby-value">-2</span> <span class="ruby-operator">:</span> <span class="ruby-value">2</span>, <span class="ruby-identifier">prec</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">infinite?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">pi</span> <span class="ruby-operator">/</span> (<span class="ruby-identifier">neg</span> <span class="ruby-operator">?</span> <span class="ruby-value">-4</span> <span class="ruby-operator">:</span> <span class="ruby-value">4</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">round</span>(<span class="ruby-identifier">prec</span>) <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">x</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;1&quot;</span>).<span class="ruby-identifier">div</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">prec</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">inv</span> = <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">x</span> = (<span class="ruby-value">-1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sqrt</span>(<span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">x</span><span class="ruby-operator">**</span><span class="ruby-value">2</span>, <span class="ruby-identifier">prec</span>))<span class="ruby-operator">/</span><span class="ruby-identifier">x</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">dbl</span> = <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0.5</span>
  <span class="ruby-identifier">n</span>    = <span class="ruby-identifier">prec</span> <span class="ruby-operator">+</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
  <span class="ruby-identifier">y</span> = <span class="ruby-identifier">x</span>
  <span class="ruby-identifier">d</span> = <span class="ruby-identifier">y</span>
  <span class="ruby-identifier">t</span> = <span class="ruby-identifier">x</span>
  <span class="ruby-identifier">r</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;3&quot;</span>)
  <span class="ruby-identifier">x2</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">n</span>)
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">m</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">y</span>.<span class="ruby-identifier">exponent</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">exponent</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
    <span class="ruby-identifier">t</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">t</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x2</span>,<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">d</span> = <span class="ruby-identifier">t</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">r</span>,<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">y</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">d</span>
    <span class="ruby-identifier">r</span> <span class="ruby-operator">+=</span> <span class="ruby-value">2</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">y</span> <span class="ruby-operator">*=</span> <span class="ruby-value">2</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">dbl</span>
  <span class="ruby-identifier">y</span> = <span class="ruby-identifier">pi</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">y</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">inv</span>
  <span class="ruby-identifier">y</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">y</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">neg</span>
  <span class="ruby-identifier">y</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-cos" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cos(decimal, numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the cosine of <code>decimal</code> to the specified number of digits of precision, <code>numeric</code>.</p>

<p>If <code>decimal</code> is Infinity or NaN, returns NaN.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-identifier">cos</span>(<span class="ruby-constant">BigMath</span>.<span class="ruby-constant">PI</span>(<span class="ruby-value">4</span>), <span class="ruby-value">16</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;-0.999999999999999999999999999999856613163740061349e0&quot;</span>
</pre>

                              <div class="method-source-code" id="cos-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 102</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cos</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">prec</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Zero or negative precision for cos&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;NaN&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">infinite?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nan?</span>
  <span class="ruby-identifier">n</span>    = <span class="ruby-identifier">prec</span> <span class="ruby-operator">+</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
  <span class="ruby-identifier">one</span>  = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;1&quot;</span>)
  <span class="ruby-identifier">two</span>  = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;2&quot;</span>)
  <span class="ruby-identifier">x</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">x</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">twopi</span> = <span class="ruby-identifier">two</span> <span class="ruby-operator">*</span> <span class="ruby-constant">BigMath</span>.<span class="ruby-constant">PI</span>(<span class="ruby-identifier">prec</span>))
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">30</span>
      <span class="ruby-identifier">x</span> <span class="ruby-operator">%=</span> <span class="ruby-identifier">twopi</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">x</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">twopi</span> <span class="ruby-keyword">while</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">twopi</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">x1</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">x2</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">n</span>)
  <span class="ruby-identifier">sign</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">y</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">d</span> = <span class="ruby-identifier">y</span>
  <span class="ruby-identifier">i</span> = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;0&quot;</span>)
  <span class="ruby-identifier">z</span> = <span class="ruby-identifier">one</span>
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">m</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">y</span>.<span class="ruby-identifier">exponent</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">exponent</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
    <span class="ruby-identifier">sign</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">sign</span>
    <span class="ruby-identifier">x1</span>  = <span class="ruby-identifier">x2</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x1</span>,<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">i</span>  <span class="ruby-operator">+=</span> <span class="ruby-identifier">two</span>
    <span class="ruby-identifier">z</span>  <span class="ruby-operator">*=</span> (<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">one</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">i</span>
    <span class="ruby-identifier">d</span>   = <span class="ruby-identifier">sign</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x1</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">z</span>,<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">y</span>  <span class="ruby-operator">+=</span> <span class="ruby-identifier">d</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">y</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sin" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sin(decimal, numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the sine of <code>decimal</code> to the specified number of digits of precision, <code>numeric</code>.</p>

<p>If <code>decimal</code> is Infinity or NaN, returns NaN.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-identifier">sin</span>(<span class="ruby-constant">BigMath</span>.<span class="ruby-constant">PI</span>(<span class="ruby-value">5</span>)<span class="ruby-operator">/</span><span class="ruby-value">4</span>, <span class="ruby-value">5</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;0.70710678118654752440082036563292800375e0&quot;</span>
</pre>

                              <div class="method-source-code" id="sin-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sin</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">prec</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Zero or negative precision for sin&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;NaN&quot;</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">infinite?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nan?</span>
  <span class="ruby-identifier">n</span>    = <span class="ruby-identifier">prec</span> <span class="ruby-operator">+</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
  <span class="ruby-identifier">one</span>  = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;1&quot;</span>)
  <span class="ruby-identifier">two</span>  = <span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&quot;2&quot;</span>)
  <span class="ruby-identifier">x</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">x</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">neg</span> = <span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">twopi</span> = <span class="ruby-identifier">two</span> <span class="ruby-operator">*</span> <span class="ruby-constant">BigMath</span>.<span class="ruby-constant">PI</span>(<span class="ruby-identifier">prec</span>))
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">30</span>
      <span class="ruby-identifier">x</span> <span class="ruby-operator">%=</span> <span class="ruby-identifier">twopi</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">x</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">twopi</span> <span class="ruby-keyword">while</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">twopi</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">x1</span>   = <span class="ruby-identifier">x</span>
  <span class="ruby-identifier">x2</span>   = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">n</span>)
  <span class="ruby-identifier">sign</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">y</span>    = <span class="ruby-identifier">x</span>
  <span class="ruby-identifier">d</span>    = <span class="ruby-identifier">y</span>
  <span class="ruby-identifier">i</span>    = <span class="ruby-identifier">one</span>
  <span class="ruby-identifier">z</span>    = <span class="ruby-identifier">one</span>
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">m</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">y</span>.<span class="ruby-identifier">exponent</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d</span>.<span class="ruby-identifier">exponent</span>).<span class="ruby-identifier">abs</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
    <span class="ruby-identifier">m</span> = <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">double_fig</span>
    <span class="ruby-identifier">sign</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">sign</span>
    <span class="ruby-identifier">x1</span>  = <span class="ruby-identifier">x2</span>.<span class="ruby-identifier">mult</span>(<span class="ruby-identifier">x1</span>,<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">i</span>  <span class="ruby-operator">+=</span> <span class="ruby-identifier">two</span>
    <span class="ruby-identifier">z</span>  <span class="ruby-operator">*=</span> (<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">one</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">i</span>
    <span class="ruby-identifier">d</span>   = <span class="ruby-identifier">sign</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x1</span>.<span class="ruby-identifier">div</span>(<span class="ruby-identifier">z</span>,<span class="ruby-identifier">m</span>)
    <span class="ruby-identifier">y</span>  <span class="ruby-operator">+=</span> <span class="ruby-identifier">d</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">neg</span> <span class="ruby-operator">?</span> <span class="ruby-operator">-</span><span class="ruby-identifier">y</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">y</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sqrt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sqrt(decimal, numeric) &rarr; BigDecimal
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Computes the square root of <code>decimal</code> to the specified number of digits of precision, <code>numeric</code>.</p>

<pre class="ruby"><span class="ruby-constant">BigMath</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-constant">BigDecimal</span>(<span class="ruby-string">&#39;2&#39;</span>), <span class="ruby-value">16</span>).<span class="ruby-identifier">to_s</span>
<span class="ruby-comment">#=&gt; &quot;0.1414213562373095048801688724e1&quot;</span>
</pre>

                              <div class="method-source-code" id="sqrt-source">
            <pre><span class="ruby-comment"># File bigdecimal/lib/bigdecimal/math.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sqrt</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">prec</span>)
  <span class="ruby-identifier">x</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">prec</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

